<template>
  <div class="main-content">
    <div class="auto-1620723992129 m-layer z-show" style="top: 175px; left: 503px;">
      <div class="zbar" id="auto-id-mqM61Uzr8iT4p2Xq">
        <div class="zttl f-thide">登录</div>
        <span class="zcls" title="关闭窗体" id="auto-id-9Wdfes77szMIghmZ">×</span>
      </div>
      <div class="zcnt">
        <div class="lyct lyct-1 f-pr" id="auto-id-NDPkikhaHxrCwAwJ">
        <div class="lg n-login-scan" id="login-qrcode" style="min-height:332px">
          <div class="cnt">
            <div class="main j-flag">
              <div class="f-cb">
                <div class="phone"></div>
                <div class="right">
                  <div class="title">扫码登录</div>
                  <div class="qr">
                    <div class="tip f-dn f-link j-flag" style="display:none;">
                      <p>二维码已失效</p>
                      <a class="u-btn2" href="javascript:;" data-action="refresh">点击刷新</a>
                    </div>
                    <div class="canvas f-pen j-flag" title="http://music.163.com/login?codekey=0c83912c-3f8c-487b-b96f-be56ce6a8fbd">
                      <img alt="Scan me!" :src="qrImg">
                    </div>
                  </div>
                  <p class="txt j-flag">使用&nbsp;
                    <a class="download-link" href="/download" target="_blank">网易云音乐APP</a>
                    &nbsp;扫码登录
                  </p>
                </div>
              </div>
            </div>
            <div class="suc j-flag f-hide">
              <div class="suc-icon"></div>
              <p class="suc-txt">扫描成功</p>
            </div>
            <p class="confirm j-flag f-hide">请在手机上确认登录</p>
            <div id="otherbtn" class="otherbtn">
              <a class="u-btn2 other" @click="$router.push('/login/account')" data-action="switch">选择其他登录模式</a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  </div>
</template>

<script>
export default {
  name: 'PlaymusicQr',
  data() {
    return {
      qrImg: '',
      key: '',
    };
  },
  methods: {
    pulling(key) {
      const timer = setTimeout(() => {
        // eslint-disable-next-line consistent-return
        this.$checkQrStatus({ key }).then((res) => {
          if (res.data.code === 801) {
            // eslint-disable-next-line no-console
            this.pulling(key);
          } else if (res.data.code === 802) {
            this.pulling(key);
          } else if (res.data.code === 803) {
            clearTimeout(timer);
            // eslint-disable-next-line no-shadow
            this.$loginStatus({ cookie: res.data.cookie }).then((res) => {
            // eslint-disable-next-line no-console
              if (res.data.data.code === 200) {
                this.$store.set('user', res.data.data);
                // eslint-disable-next-line no-console
                console.log(this.$route.params.originRouteName);
                // console.log(res.data.profile.avatarUrl);
                this.$router.push({ name: this.$route.params.originRouteName });
              }
            }).catch((err) => {
              // eslint-disable-next-line no-console
              console.log(err);
            });
          } else if (res.data.code === 800) {
            this.Refresh = true;
            clearTimeout(timer);
          }
          // eslint-disable-next-line no-shadow
        //   return this.$loginStatus({ cookie: res.data.cookie });
        }).catch((err) => {
          // eslint-disable-next-line no-console
          console.log(err);
        });
      }, 1000);
    },
  },
  created() {
    // eslint-disable-next-line consistent-return
    this.$qrKey().then((res) => {
      if (res.data.data.code === 200) {
        this.key = res.data.data.unikey;
        return this.$qrInfo({ key: res.data.data.unikey, qrimg: true });
      }
    }).then((res) => {
      if (res.data.code === 200) {
        this.qrImg = res.data.data.qrimg;
        this.pulling(this.key);
      }
    }).catch((err) => {
      // eslint-disable-next-line no-console
      console.log(err);
    });
  },
};
</script>

<style lang="scss" scoped>
div.m-layer {
    position: absolute;
    z-index: 9998;
    width: 530px;
    border-radius: 4px;
    box-shadow: 0 5px 16px rgba(0, 0, 0,.8);
    border: none;
}
.auto-1620723992129 {
    position: absolute;
    z-index: 1000;
    border: 1px solid #aaa;
    background: #fff;
}
div.m-layer .zbar {
    position: relative;
    z-index: 10;
    border-bottom: 1px solid #191919;
    border-radius: 4px 4px 0 0;
    background: #2d2d2d;
}
div.m-layer .zbar, div.m-layer .zttl {
    cursor: move;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
div.m-layer .zttl {
    padding-right: 45px;
    margin: 0;
    height: 38px;
    line-height: 38px;
    padding-left: 18px;
    border-radius: 3px 3px 0 0;
    font-weight: bold;
    font-size: 14px;
    color: #fff;
    background-position: 50% 0;
    // _background-image: none;
}
div.m-layer .zbar, div.m-layer .zttl {
    cursor: move;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
div.m-layer div.zcnt {
    padding: 0;
    border: 1px solid #878787;
    border-width: 0 1px 1px;
    border-radius: 0 0 4px 4px;
    background: #fff;
}
body, textarea, select, input, button {
    font-size: 12px;
    // color: #333;
    font-family: Arial, Helvetica, sans-serif;
    -webkit-text-size-adjust: none;
}
html, body {
    width: 100%;
    height: 100%;
    border: 0;
    word-wrap: break-word;
    word-break: break-word;
}
div.m-layer .lyct-1 {
    padding: 0;
}
.f-pr {
    position: relative;
    zoom: 1;
}
.f-hide, .js-hide {
    display: none !important;
}
.n-log2-1 {
    padding: 40px 0 39px;
}
.f-cb:after {
    clear: both;
    content: '.';
    display: block;
    height: 0;
    visibility: hidden;
}
.n-log2 .u-main {
    float: left;
    width: 224px;
    padding: 0 35px 3px 40px;
    border-right: 1px dotted #ccc;
}
.n-log2 .u-main .u-plt {
    height: 120px;
    // background: url(../../style/web2/img/platform.png?ad7781f…) no-repeat 13px 0;
}
.f-mgt10 {
    margin-top: 10px;
}
.n-log2 .u-main .u-btn2 {
    width: 219px;
}
.u-btn2-2 {
    color: #fff;
    background-position: right -428px;
}
.u-btn2, .u-btn2:hover {
    text-decoration: none;
}
.u-btn2 {
    padding: 0 5px 0 0;
    white-space: nowrap;
}
.u-btn2, .u-btn2 i {
    display: inline-block;
    *display: inline;
    *zoom: 1;
    height: 31px;
    line-height: 31px;
    overflow: hidden;
    *line-height: 32px;
    vertical-align: top;
    text-align: center;
    cursor: pointer;
}
.n-log2 .u-alt {
    float: left;
    padding: 3px 0 3px 39px;
    margin-top: -15px;
}
.n-log2 .u-alt li {
    margin-top: 15px;
}
li, s {
    list-style: none;
}
.n-log2 .u-alt li a {
    font-size: 12px;
    color: #333;
    line-height: 38px;
}
a, a *, .f-hand, .f-hand * {
    cursor: pointer;
}
.n-log2 .u-alt li .u-mlg2 {
    margin-right: 14px;
}
.u-mlg2-wx {
    background-position: -150px -670px;
}
.u-mlg2 {
    width: 38px;
    height: 38px;
}
.u-slg, .u-slg2, .u-slg3, .u-blg, .u-mlg, .u-mlg2, .u-importlg, .u-errlg {
    display: inline-block;
    vertical-align: middle;
}
em, i {
    font-style: normal;
    text-align: left;
    font-size: inherit;
}
.n-login-scan .main .phone {
    float: left;
    margin-left: 101px;
    width: 125px;
    height: 220px;
    background: url(./QQ图片20210511182748.jpg);
    background-size: contain;
}
.n-login-scan .main .qr {
    background: #fff;
}
.n-login-scan .main .qr {
    width: 130px;
    height: 130px;
    padding: 4px;
    margin: 13px auto;
    position: relative;
}
n-login-scan .main .tip {
    background: rgba(255, 255, 255, 0.9);
}
.n-login-scan .main .tip {
    z-index: 1;
    font-size: 14px;
}
.n-login-scan .main .tip {
    background: rgba(255, 255, 255, 0.9);
}
.n-login-scan .main .tip {
    z-index: 1;
    font-size: 14px;
}
.f-hide, .js-hide {
    display: none !important;
}
.f-link {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    width: 100%;
    height: 100%;
}
.n-login-scan .right .title {
    font-size: 18px;
    font-weight: 500;
}
.n-login-scan .cnt {
    margin: 0 auto;
    padding: 38px 0 20px;
    text-align: center;
}
.n-login-scan .main .tip p {
    margin: 45px auto 6px;
    font-size: 12px;
    color: rgba(0,0,0,0.80);
    font-weight: 500;
}
.n-login-scan .main .tip a {
    display: block;
    margin: 0 auto;
    padding-right: 0;
    width: 64px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    border-radius: 4px;
    background: linear-gradient(180deg, #81DD81 0%, #55A055 100%);
    border: 1px solid #5BAF5B;
    box-shadow: inset 0 -1px 1px 1px rgba(185, 230, 185,.31);
    color: #fff;
    font-size: 12px;
}
.u-btn2, .u-btn2:hover {
    text-decoration: none;
}
.u-btn2 {
    padding: 0 5px 0 0;
    white-space: nowrap;
}
.u-btn2, .u-btn2 i {
    display: inline-block;
    height: 31px;
    line-height: 31px;
    overflow: hidden;
    vertical-align: top;
    text-align: center;
    cursor: pointer;
}
.n-login-scan .main .qr .f-pen {
    pointer-events: none !important;
}
img, .txt {
    border: 0;
}
.n-login-scan .main .txt {
    font-size: 12px;
    top: 181px;
    width: 200px;
    right: -15px;
    left: auto;
    line-height: 17px;
    color: rgba(0, 0, 0, 0.4);
}
.n-login-scan .main p {
    text-align: center;
}
.n-login-scan .right {
    float: left;
    margin-left: 25px;
}
.f-cb:after {
    clear: both;
    content: '.';
    display: block;
    height: 0;
    visibility: hidden;
}
.n-login-scan .main {
    position: relative;
    margin: 0 auto;
}
.n-login-scan .suc {
    color: #999;
}
.n-login-scan .suc {
    width: 100%;
}
.f-hide, .js-hide {
    display: none !important;
}
.n-login-scan .suc-icon {
    width: 140px;
    height: 140px;
    background-size: contain;
    margin: 0 auto;
}
.n-login-scan .suc-txt {
    margin-top: 12px;
    font-size: 18px;
    font-weight: 450;
    line-height: 24px;
    color: rgba(0, 0, 0, 0.8);
}
.n-login-scan .otherbtn {
    height: 28px;
}
.n-login-scan .other {
    display: block;
    width: 118px;
    height: 100%;
    margin: 20px auto 0;
    padding-right: 0;
    font-size: 12px;
    border: 1px solid #979797;
    border-radius: 15px;
    line-height: 28px;
    text-align: center;
    color: rgba(0,0,0,0.80);
}
.n-login-scan .confirm {
    color: #333;
}
.n-login-scan .confirm {
    margin-top: 4px;
    margin-bottom: 30px;
    font-size: 14px;
}
.f-hide, .js-hide {
    display: none !important;
}
div.m-layer .zcls {
    position: absolute;
    z-index: 20;
    top: 16px;
    right: 20px;
    width: 10px;
    height: 10px;
    overflow: hidden;
    text-indent: -9999px;
    cursor: pointer;
    background-position: 0 -95px;
}
.n-login-scan .download-link {
    color: #0c73c2;
}
a, a *, .f-hand, .f-hand * {
    cursor: pointer;
}
a {
    text-decoration: none;
}
.f-thide {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-wrap: normal;
}
.canvas{
    display: flex;
    align-items: center;
    justify-content: center;
    height:122px;
    width: 122px;
    img{
        height: 100%;
        width: 100%;
    }
}
</style>
